/**
 * 
 */
package model.turtle;

/**
 * 
 */
public class Position {
    public static final int MAX = 360;
    protected double x;
    protected double y;
    protected double direction;

    public int getX() {
        return (int) Math.round(x);
    }

    public int getY() {
        return (int) Math.round(y);
    }

    public void setX(int _x) {
        x = _x;
    }

    public void setY(int _y) {
        y = _y;
    }

    public Position(int x, int y, int d) {
        this.x = x;
        this.y = y;
        setDirection(d);
    }

    public Position(Position p) {
        x = p.x;
        y = p.y;
        direction = p.direction;
    }

    public int getDirection() {
        return (int) Math.round(direction);
    }

    public void setDirection(int d) {
        this.direction = d % MAX;
        if (this.direction < 0)
            this.direction += MAX; // Deal with odd behavior of mod.
    }

    @Override
    public boolean equals(Object o) {
        if (!(o instanceof Position))
            return false;
        Position p = (Position) o;
        return getX() == p.getX() && getY() == p.getY()
                && getDirection() == p.getDirection();
    }

    @Override
    public String toString() {
        return String.format("[%d, %d, %d]", getX(), getY(), getDirection());
    }
}
